//
//  MJ_ProjectDetailCell.m
//  UEAssistant
//
//  Created by mac on 2018/1/10.
//  Copyright © 2018年 youyixinxi. All rights reserved.
//

#import "MJ_ProjectDetailCell.h"

@interface MJ_ProjectDetailCell ()<LWAsyncDisplayViewDelegate>

@property (strong, nonatomic)LWAsyncDisplayView *asyncDisplayView;

@end

@implementation MJ_ProjectDetailCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.asyncDisplayView];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.asyncDisplayView.frame = CGRectMake(0, 0, Screen_Width, self.layout.cellHeight);
}

- (void)setLayout:(MJ_ProjectDetailLayout *)layout {
    if (_layout != layout) {
        _layout = layout;
        self.asyncDisplayView.layout = layout;
    }
}


- (void)extraAsyncDisplayIncontext:(CGContextRef)context
                              size:(CGSize)size
                       isCancelled:(LWAsyncDisplayIsCanclledBlock)isCancelled {
    if (!isCancelled()) {
        
        //设置虚线颜色
        CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"#e0e0e0"].CGColor);
        //设置虚线宽度
        CGContextSetLineWidth(context, 1);
        //设置虚线绘制起点
        CGContextMoveToPoint(context, 8, self.frame.size.height-1.0);
        //设置虚线绘制终点
        CGContextAddLineToPoint(context, self.frame.size.width-16, self.frame.size.height-1.0);
        //设置虚线排列的宽度间隔:下面的arr中的数字表示先绘制3个点再绘制1个点
        CGFloat arr[] = {1,1};
        //下面最后一个参数“2”代表排列的个数。
        CGContextSetLineDash(context, 0, arr, 2);
        CGContextDrawPath(context, kCGPathStroke);
        
    }
}



- (LWAsyncDisplayView *)asyncDisplayView {
    if (!_asyncDisplayView) {
        _asyncDisplayView = [[LWAsyncDisplayView alloc] initWithFrame:CGRectZero];
        _asyncDisplayView.displaysAsynchronously = NO;
        _asyncDisplayView.delegate = self;
    }
    return _asyncDisplayView;
}

@end
